<template>
  <div class="content">
    <div class="content-main">
      <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
        <el-tab-pane label="科技成果" name="1"></el-tab-pane>
        <el-tab-pane label="科普知识" name="2"></el-tab-pane>
      </el-tabs>
      <div v-if="activeName === '1'" class="btn-list-wrap">
        <div>
          <span>区域: </span>
          <el-select v-model="areaValue" placeholder="请选择" clearable style="width: 200px">
            <el-option
              v-for="item in areaDictCodes"
              :key="item.dictionaryCode"
              :label="item.dictionaryName"
              :value="item.dictionaryCode"
            />
          </el-select>
        </div>
        <div>
          <span>产业领域: </span>
          <el-select v-model="industryOpValue1" placeholder="请选择" clearable style="width: 200px">
            <el-option
              v-for="item in industryCodes"
              :key="item.dictionaryCode"
              :label="item.dictionaryName"
              :value="item.dictionaryCode"
            />
          </el-select>
        </div>
        <span>计量专业领域: </span>
        <el-select v-model="professionOpValue1" placeholder="请选择" clearable style="width: 200px">
          <el-option
            v-for="item in professionCodes"
            :key="item.dictionaryCode"
            :label="item.dictionaryName"
            :value="item.dictionaryCode"
          />
        </el-select>
        <div>
          <el-button type="primary" @click="getAchievementList" class="button-query"
            >查询</el-button
          >
        </div>
      </div>
      <div v-if="activeName === '2'" class="btn-list-wrap">
        <div>
          <span>产业领域: </span>
          <el-select v-model="industryOpValue2" placeholder="请选择" clearable style="width: 200px">
            <el-option
              v-for="item in industryCodes"
              :key="item.dictionaryCode"
              :label="item.dictionaryName"
              :value="item.dictionaryCode"
            />
          </el-select>
          <el-button type="primary" @click="getArticleList" class="button-query">查询</el-button>
        </div>
      </div>
      <div class="list-wrap">
        <div class="list-info" v-for="(item, index) in listData" :key="index">
          <div class="list-info-title">{{ item.title }}</div>
          <div class="list-info-content">
            <!-- <span class="list-info-info" v-html="item.technicalHighlights"></span> -->
            <span class="list-info-info"></span>
            <span class="list-info-btn" @click="jumpPage(item)">查看</span>
          </div>
          <div class="list-info-type">
            <span class="list-info-type-title"
              >{{ activeName === '1' ? '产业中心' : '来源' }}:
            </span>
            <p class="list-info-type-value">{{
              activeName === '1' ? item.centerName : item.source
            }}</p>
          </div>
        </div>
        <div class="pagination">
          <el-pagination
            :current-page="queryParams.pageNum"
            :page-size="queryParams.pageSize"
            background
            layout="prev, pager, next, jumper, total"
            :total="queryParams.total"
            @current-change="currentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { TopRight } from '@element-plus/icons-vue'
import { cmsAchievement, cmsArticle } from '@/api'
const dictStore = useDictStore()
dictStore.fetchDictionary()
const industryCodes = computed(() => {
  return dictStore.getDict?.filter((item) => item.siteCode === 'JLY_INDUSTRY_CODE')
})
const areaDictCodes = computed(() => {
  return dictStore.getDict?.filter((item) => item.siteCode === 'JLY_AREA_CODE')
})
const professionCodes = computed(() => {
  return dictStore.getDict?.filter((item) => item.siteCode === 'JLY_PROFESSION_CODE')
})

const activeName = ref('1')
const queryParams = reactive({
  name: '',
  pageNum: 1,
  pageSize: 10,
  total: 0
})
const areaValue = ref('')
const industryOpValue1 = ref('')
const industryOpValue2 = ref('')
const professionOpValue1 = ref('')

function getArticleList() {
  cmsArticle({
    pageNum: queryParams.pageNum,
    pageSize: queryParams.pageSize,
    articleType: 'SP', //科普知识
    industryCode: industryOpValue2.value
  }).then(({ data }) => {
    listData.value = data.list
  })
}

function handleClick(val) {
  queryParams.pageNum = 1
  queryParams.pageSize = 10
  queryParams.total = 0
  if (val.paneName === '1') {
    getAchievementList()
  } else {
    getArticleList()
  }
}

const router = useRouter()

function jumpPage(item) {
  if (activeName.value === '2') {
    router.push({ path: 'technologyAssociationDetails2', query: { id: item.id } })
  } else {
    router.push({ path: 'technologyAssociationDetails', query: { id: item.id } })
  }
}

function currentChange(val) {
  queryParams.pageNum = val
  getAchievementList()
}

const listData = ref([])

function getAchievementList() {
  cmsAchievement({
    pageNum: queryParams.pageNum,
    pageSize: queryParams.pageSize,
    areaCode: areaValue.value,
    industryCode: industryOpValue1.value,
    areaCode: areaValue.value,
    professionCode: professionOpValue1.value
  }).then(({ data }) => {
    listData.value = data.list
    queryParams.total = data.total
  })
}

onMounted(() => {
  getAchievementList()
})
</script>
<style lang="scss" scoped>
.content {
  background-color: #f6faff;
}

.content-main {
  width: 1200px;
  height: 1700px;
  margin: auto;

  .list-wrap {
    .list-info {
      margin-bottom: 20px;
      padding: 20px;
      background-color: #fff;

      .list-info-title {
        font-size: 18px;
        color: #333;
      }

      .list-info-content {
        padding: 10px 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        height: 40px;
        font-size: 12px;
        color: #8992a9;
        //间隔10px
        gap: 10px;

        .list-info-info {
          padding: 0 20px 0 0;
          width: 100%;
          height: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          //超过2行显示省略号
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }

        .list-info-btn {
          display: flex;
          justify-content: center;
          align-items: center;
          width: 76px;
          height: 30px;
          background: #1d5ede;
          font-size: 16px;
          color: #fff;
          cursor: pointer;
        }
      }

      .list-info-type {
        display: flex;
        align-items: center;
        margin-top: 10px;
        font-size: 14px;
        color: #8992a9;

        .list-info-type-title {
        }

        .list-info-type-value {
          margin: 0;
          margin-left: 10px;
          padding: 2px 6px;
          color: #1d5ede;
          background: #eff4ff;
        }
      }
    }
  }

  .btn-list-wrap {
    display: flex;
    align-items: center;
    margin-bottom: 20px;

    span {
      margin: 0 10px;
    }
  }

  .pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 10px;
  }
  .button-query {
    margin-left: 15px;
  }
}
</style>
